<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!--********************************************************************
* 该示例需要引入
* UGCWasm (https://iclient.supermap.io/web/libs/ugcwasm/1.0.1/UGCWasmAll.js)
*********************************************************************-->
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title data-i18n="resources.title_ugcGeodesicDistance"></title>
    <style>
      body {
        margin: 0;
        overflow: hidden;
        background: #fff;
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
      }
      #toolbar {
        position: absolute;
        top: 50px;
        right: 10px;
        width: 280px;
        text-align: center;
        z-index: 10000;
        border-radius: 4px;
      }
      .leaflet-popup-content {
        width: 280px;
        font-size: 16px !important;
      }
    </style>
  </head>

  <body>
    <div id="toolbar" class="panel panel-primary">
      <div class="panel-heading">
        <h5 class="panel-title text-center">计算测地线的长度</h5>
      </div>
      <div class="panel-body content">
        <input type="button" class="btn btn-default" value="计算" onclick="search()" />&nbsp;
      </div>
    </div>
    <div id="map" style="width: 100%; height: 100%"></div>
    <script type="text/javascript" include="bootstrap-css" src="../js/include-web.js"></script>
    <script type="text/javascript" include="ugcwasm" src="../../dist/leaflet/include-leaflet.js"></script>
    <script>
      var map, popup, marker, line;
      popup = L.popup();
      var map, bufferLayer;
      var host = window.isLocal ? window.server : 'https://iserver.supermap.io';
      var url = host + '/iserver/services/map-world/rest/maps/World';
      L.supermap
        .initMap(url, {
          mapOptions: {
            center: [30, 120],
            zoom: 6
          }
        })
        .then((res) => {
          map = res.map;
          addFeatures();
        });

      function addFeatures() {
        line = {
          type: 'Feature',
          geometry: {
            type: 'LineString',
            coordinates: [
              [120, 30],
              [125, 30]
            ]
          }
        };
        L.geoJSON(line, {
          style: function () {
            return {
              weight: 3,
              color: 'blue'
            };
          }
        }).addTo(map);
      }

      function search() {
        clearPopup();
        var geometryAnalysis = new L.supermap.GeometryAnalysis();
        var distance;
        distance = geometryAnalysis.computeGeodesicDistance(
          [
            [120, 30],
            [125, 30]
          ],
          6378137,
          0.0033528106647475,
          'KILOMETER'
        );
        popup
          .setLatLng([30, 123])
          .setContent('长度为: ' + distance + '千米')
          .openOn(map);
      }

      function clearPopup() {
        map.closePopup();
      }
    </script>
  </body>
</html>
